/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-08 15:07:43
 * Copyright (c) 2015- joysuch-版权所有
 */
package com.joysuch.wwyt.bp.controller;

import com.joysuch.wwyt.bp.bean.contractor.BpContractorViolationRecordBean;
import com.joysuch.wwyt.bp.service.BpContractorViolationRecordsManagementService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 违章记录管理
 * @author sumeiqi
 * 2021-01-12
 */
@RestController
@RequestMapping("/bp/contractor/violation-records-management")
@Api(tags = "违章记录管理")
public class BpContractorViolationRecordsManagementController {

    @Autowired
    private BpContractorViolationRecordsManagementService service;

    @GetMapping("page")
    @ApiOperation(value = "违章记录管理-分页查询", response = BpContractorViolationRecordBean.class)
//    @RequiresPermissions("bp:contractor:violation:records:management:page")
    public ResultBean page(Pageable page, String contractorName) {
        Page<BpContractorViolationRecordBean> data = service.page(page, contractorName);
        return ResultBean.pageData(data.getContent(), data.getTotalElements());
    }

    @GetMapping("get")
    @ApiOperation(value = "违章记录管理-单体查询", response = BpContractorViolationRecordBean.class)
//    @RequiresPermissions("bp:contractor:violation:records:management:get")
    public ResultBean getById(@RequestParam Long id) {
        return service.getById(id);
    }

    /**
     * 添加新增字段：违章类型、处罚金额、处罚积分、附件
     * @param bean
     * @return
     */
    @PostMapping("save")
    @ApiOperation(value = "违章记录管理-新增/修改", response = BpContractorViolationRecordBean.class)
    @RequiresPermissions("bp:contractor:violation:records:management:save")
    public ResultBean save(@Valid @RequestBody BpContractorViolationRecordBean bean) {
        return service.save(bean);
    }

    @GetMapping("delete")
    @ApiOperation(value = "违章记录管理-删除", response = BpContractorViolationRecordBean.class)
    @RequiresPermissions("bp:contractor:violation:records:management:delete")
    public ResultBean delete(@RequestParam Long id) {
        return service.delete(id);
    }

}
